<template>
  <dialog_item :dialogTitle="$t('add_admin_list')" @onBtnDialogClick="onBtnDialogClick" :visible.sync="dialogVisible"  :isShowConfirmBtn="true">
    <el-container>
        <el-main class="paddingLeft0">
          <el-row :gutter="20">
            <el-col :span="16">
              <el-form :inline="true" :model="searchdata" size="mini" class="demo-form-inline"  @submit.native.prevent >
                <el-form-item >
                  <el-input v-model="searchdata.data.name" :placeholder="$t('username')"  @keyup.enter.native="searchTableData"></el-input>
                </el-form-item>
                <el-form-item>
                <el-button @click="searchTableData" type="primary" plain>{{$t('query')}}</el-button>
                <el-button @click="resetSearchTableData">{{$t('reset')}}</el-button>
                </el-form-item>
              </el-form>
            </el-col>
          </el-row>
          <!-- 用户列表 -->
          <el-table 
            stripe
            :data="tableData.datas" 
            :row-key="handleReserve"
            @selection-change="handleSelectionChange" 
            height="300px" 
            ref="multipleTable"
            header-cell-class-name="tableHeaderbg"
            aria-setsize="small"
          >
            <el-table-column type="selection" width="55"  :reserve-selection="true"></el-table-column>
            <el-table-column prop="name" :label="$t('user_name')"></el-table-column>
            <el-table-column prop="loginno" :label="$t('loginno')"></el-table-column>
            <el-table-column prop="email" :label="$t('email')"></el-table-column>
          </el-table>
          <!-- 分页 -->
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="searchTableData"
            :current-page.sync="searchdata.currpage"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="searchdata.pagelines"
            layout="prev, pager, next, total, sizes"
            background
            :total="tableData.rowCount?tableData.rowCount:0"
          ></el-pagination>
        </el-main>
    </el-container>
    </dialog_item>
</template>

<script>
export default {
  props: ["visible"],
  data() {
    return {
      searchdata: {
        domainid: this.$route.query.domainid,
        superiorname: "",
        departmentid: "",
        loginno: "",
        roleid: "",
        currpage: 1,
        pagelines: 10,
        orderby: "",
        data:{
          name: "",
        }
      },
      tableData: [],
      multipleSelection: []
    };
  },
  computed: {
    dialogVisible: {
      get() {
        return this.visible;
      },
      set(val) {
        this.$emit("update:visible", val);
      }
    }
  },
  created() {
    this.searchTableData();
  },
  methods: {
    onBtnDialogClick(name){
      if(name=='confirm'){
        this.onOk()
      }
    },
    resetSearchTableData(){
      this.searchdata.data.name='';
      this.searchTableData();
    },
    handleReserve(row){
      return row.id
    },
    onOk() {
      this.dialogVisible = false;
      this.$emit("select-ok", this.multipleSelection);
    },
    onCancel() {
      this.dialogVisible = false;
    },
    handleSelectionChange(rows){
      this.multipleSelection = rows;
    },
    handleClose() {
      this.dialogVisible = false;
    },
    handleSizeChange(size){
      this.searchdata.pagelines=size;
      this.searchTableData();
    },
    searchTableData() {
      this.$api.getnoDomainManagers(this.searchdata, {
        onSucess: resp => {
          this.tableData = resp.data.data;
          this.$nextTick(() => {
            this.$refs.multipleTable.doLayout()
          })
        }
      });
    },
  }
};
</script>

<style lang="scss" scoped>
</style>